//
// Created by cxh on 2021/10/21.
//
#include <iostream>
#include "test/Test.h"
#include "objects/OrthoCamera.h"
#include "renderer/MRender.h"
#include "objects/mesh/Triangle.h"
#include "objects/mesh/Model.h"
#include "objects/PerspCamera.h"
#include "objects/mesh/Cube.h"
#include "helpers/GridHelper.h"

void testMRender();

void testStringSplit();

int main() {
    String s = "mRender start.";
    std::cout<< s.c_str() <<std::endl;

    //测试字符串问题
    //testStringSplit();

    //test01();
    //test02();
    //testString();
    testMRender();

    return EXIT_SUCCESS;
}

void testMRender(){

    MRender * mRender = MRender::getInstance();

    // 场景
    auto *scene = new Scene();

    // 主相机
    Camera *orthCamera1 = new OrthoCamera(-10.0f, 10.0f, -10.0f, 10.0f, 1.0f, 20.0f);
    //Camera *orthCamera1 = new OrthoCamera(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 2.0f);
    orthCamera1->bFramebuffSizeCallback = false;
    scene->add(orthCamera1);
    scene->setActiveCamera(orthCamera1);

    Camera *perspCamera = new PerspCamera();
    perspCamera->location.y = 2.0f;
    perspCamera->location.z = 10.0f;
    scene->add(perspCamera);

    // 几何体
    auto cube = new Cube(1.0f);
    cube->location.z = -1.0f;
    scene->add(cube);

    auto m1 = new Model("models/what.obj");
    scene->add(m1);
    auto m2 = new Model("models/test.obj");
    scene->add(m2);
//    BufferGeometry *bufferGeometry = new BufferGeometry();
//    bufferGeometry->vertices = {
//            0.0f, 0.5f, 0.0f,
//            -0.5f, 0.0f, 0.0f,
//            0.5f, 0.0f, 0.0f
//    };
//
//    bufferGeometry->colors = {
//            1.0f, 0.0f, 0.0f, 1.0f,
//            0.0f, 1.0f, 0.0f, 1.0f,
//            0.0f, 0.0f, 1.0f, 1.0f
//    };
//
//    Object3D * colorfulTriangle = new Object3D();
//    colorfulTriangle->geometries.push_back(bufferGeometry);
//
//    scene->add(colorfulTriangle);

    // 渲染场景
    mRender->render(scene);

    // 回收
    SAFE_DELETE(scene);
}


void testStringSplit() {
    String s2 = "1 2  3     4  dsakjnka   10";
    String s3 = "  2  3     4  dsakjnka   10";
    String s4 = "  2  3     4  dsakjnka   ";
    String s5 = "woshi我是ans我是mmmm我是我i，，10";

    std::vector<String> array;
    s2.splitWithRegex("\\s+", array);
    s3.splitWithRegex("\\s+", array);
    s4.splitWithRegex("\\s+", array);
    s5.splitWithRegex("我是", array);
}









